home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / bin / imagetops < prev    next >
Text File  |  2005-09-10  |  1KB  |  70 lines

  1. #!/bin/sh
  2.  
  3. # extract file name and arguments from command line. File name
  4. # is supposed to be the last one, if it doesn't exist, then it
  5. # is assumed to be another argument.
  6. FILE=
  7. ARGS=
  8. GRAYSCALE=
  9. for arg in "$@"; do
  10.     if [ "$arg" = "-gray" ]; then
  11.         GRAYSCALE=1
  12.     else
  13.         ARGS="$ARGS $FILE"
  14.         FILE=$arg;
  15.     fi
  16. done
  17.  
  18. # we're reading from STDIN, store it into a temporary file
  19. temp=0
  20. if test -z "$FILE" -o ! -f "$FILE" ; then
  21.     ARGS="$ARGS $FILE"
  22.     FILE=`mktemp /tmp/imagetops.XXXXXX` || exit 1
  23.     cat > "$FILE"
  24.     temp=1
  25. fi
  26.  
  27. # check the file mime type, and set the command correspondingly
  28. cmd=
  29. magic=`file -bi "$FILE"`
  30. magicbase=`echo $magic | cut -f 1 -d "/"`
  31. magictype=`echo $magic | cut -f 2- -d "/"`
  32. if test "$magicbase" != "image" ; then
  33.     echo "Not an image"
  34.     exit 1;
  35. fi
  36. case $magictype in
  37.     jpeg)
  38.         cmd="jpegtopnm"
  39.         ;;
  40.     png|x-png)
  41.         cmd="pngtopnm"
  42.         ;;
  43.     bmp|x-bmp)
  44.         cmd="bmptoppm"
  45.         ;;
  46.     gif)
  47.         cmd="giftopnm"
  48.         ;;
  49.     tiff)
  50.         cmd="tifftopnm"
  51.         ;;
  52.     *)
  53.         echo "Unsupported image type: $magic"
  54.         exit 1
  55.         ;;
  56.  
  57. esac
  58.  
  59. # executing command
  60. if [ "$GRAYSCALE" = "1" ]; then
  61.     exec $cmd "$FILE" | ppmtopgm | pnmtops $ARGS
  62. else
  63.     exec $cmd "$FILE" | pnmtops $ARGS
  64. fi
  65.  
  66. # removing temporary file
  67. if test "$temp" = "1"; then
  68.     rm -f "$FILE"
  69. fi
  70.